<%@page import="efrei.ngo.util.DatabaseAccess"%>
<%@page import="efrei.ngo.entity.User"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1" deferredSyntaxAllowedAsLiteral="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Instant Message</title>

<link rel="stylesheet" href="../css/imdemo.css">
<link rel="stylesheet"
	href="../css/custom-theme/jquery-ui-1.8.18.custom.css">
<link rel="stylesheet" href="../css/button.css">
<link rel="stylesheet" href="../css/css4InstantMessage.css">

<script src="../js/jquery-1.7.1.js"></script>
<script src="../js/ui/jquery.ui.core.js"></script>
<script src="../js/ui/jquery.ui.widget.js"></script>
<script src="../js/ui/jquery.ui.tabs.js"></script>

<script src="../js/ajax-pushlet-client.js"></script>
<script src="../js/js4instantMessage.js"></script> 
<script type="text/javascript"> 
	PL._init();
	PL.joinListen('/chat'); 
	
	function onData(event) {
		if(event!=null&&event.get("M0To")==id_pi){
			//while(event)
			/*alert(event.get("M0From"));
			alert(event.get("M0MSG"));
			alert(event.get("M0Time"));*/
			showInformation(event.get("M0From"),event.get("M0MSG"),new Date(),event.get("M0IDF"));
		}
		//alert(event.get("hw")); 
	}
</script> 
</head>
<%if(request.getSession().getAttribute("user")==null){
	response.sendRedirect("..");
	return;
}
%>
<body>
	<div id="UNI" align="right"><%=((User)session.getAttribute("user")).getUsername() %></div>
	<h2>Instant Message</h2>
	<input type="hidden" id="id_pi" name="id_pi" value="<%=((User)session.getAttribute("user")).getU_id() %>">
	<table width="100%" border="0">
		<tr>
			<td width="20%"></td>
			<td></td>
		</tr>
		<tr>
			<td rowspan="2" valign="top" class="accordion">
			<div align="center">Friend List</div>
				<!-- Here is where the list of friends should be -->
				<%
					DatabaseAccess.connectToDB();
					ArrayList<User> userList=DatabaseAccess.dbGetFriendList();
					User oneU;
					String strHTML="";
				
					System.out.println("There are "+userList.size()+" People");
					for(int i=0,len=userList.size();i<len;i++){
						oneU=userList.get(i);
						
						strHTML+="<section id=\"sec_"+(i+1)+"\"><h2>"
						+"<a onClick=\"onclick_friend_list('"+oneU.getUsername()+"',"+oneU.getU_id()+");\"style=\"cursor: hand; cursor: pointer\">"+oneU.getUsername()+"</a>"
						+"</h2>"
						+"<input type=\"hidden\" id=\"sec_tab_"+(i+1)+"\" name=\"sec_tab_"+(i+1)+"\"/>"
						+"</section>";
					}
					DatabaseAccess.endConnectionToDB();
				%>
				<%=strHTML %>
				<!-- ------------------------------------------- -->
			</td>
			<td class="bg_td" align="left"
				style="vertical-align: top; background-color: #FFF;">
				<!-- ------------------- -->
				<div id="tabs" style="width: 100%">
					<ul style="font-size: 14px">
					</ul>
				</div>
			</td>
		</tr>
		<tr>
			<td align="left" class="bg_td" style="background-color: #bbb;">
				<label> <textarea name="insConSending" id="insConSending"
						rows="2" style="vertical-align: middle; width: 80%"></textarea> <input
					class="button" type="submit" name="insBtnSending"
					id="insBtnSending" value="Send"
					style="cursor: hand; cursor: pointer" onclick="onclick_insSending()">
					<input type="hidden" id="curr_name" value="" /> <input
					type="hidden" id="curr_email" value="" />
				</label>
			</td>
		</tr>
	</table>
</body>
</html>